package com.ybxx.asset.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.ybxx.asset.dao.TrenchDao;
import com.ybxx.asset.model.Structures;
import com.ybxx.asset.model.Trench;
import com.ybxx.asset.service.TrenchService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.dao.GenericDao;
import com.ybxx.core.service.impl.BaseServiceImpl;

public class TrenchServiceImpl extends BaseServiceImpl<Trench> implements
		TrenchService {
	private TrenchDao trenchDao;
	public TrenchServiceImpl(TrenchDao dao) {
		super(dao);
		this.trenchDao=dao;
		// TODO Auto-generated constructor stub
	}
	public List<Trench> queryPage(Trench trench, QueryFilter filter) {
		String hql="from Trench t where 1=1 ";
		if(trench!=null && StringUtils.isNotEmpty(trench.getZcbh())){
			hql+=" and t.zcbh like '%"+trench.getZcbh()+"%'";
		}
		if(trench!=null && StringUtils.isNotEmpty(trench.getTname())){
			hql+=" and t.tname like '%"+trench.getTname()+"%'";
		}
		if(trench!=null && StringUtils.isNotEmpty(trench.getMdept())){
			hql+=" and t.mdept like '%"+trench.getMdept()+"%'";
		}
		
		return trenchDao.findByHql(hql, null, filter.getPagingBean());
	}
	public List<Trench> exportExcel_Print(Trench trench) {
		String hql="from Trench t left join fetch t.company c where 1=1 ";
		if(trench!=null && StringUtils.isNotEmpty(trench.getZcbh())){
			hql+=" and t.zcbh like '%"+trench.getZcbh()+"%'";
		}
		if(trench!=null && StringUtils.isNotEmpty(trench.getTname())){
			hql+=" and t.tname like '%"+trench.getTname()+"%'";
		}
		if(trench!=null && StringUtils.isNotEmpty(trench.getMdept())){
			hql+=" and t.mdept like '%"+trench.getMdept()+"%'";
		}
		
		return trenchDao.findByHql(hql, null);
	}
	@Override
	public Trench get(String id) {
		String hql="from Trench t left join fetch t.company c where tid='"+id+"' ";
		return (Trench)trenchDao.findUnique(hql, null);
	}
}
